#!/usr/bin/perl
 use Linux::Inotify2 ;

 # create a new object
 my $inotify = new Linux::Inotify2
    or die "Unable to create new inotify object: $!" ;

 # create watch
 $inotify->watch ("../kuaipan-perl", IN_ALL_EVENTS)#IN_ACCESS|IN_OPEN|IN_MODIFY|)
    or die "watch creation failed" ;

 while () {
   my @events = $inotify->read;
   unless (@events > 0) {
     print "read error: $!";
     last ;
   }
   foreach my $event (@events){
	 if ($event->mask & IN_ACCESS){
		print "$event->{name} IP_ACCESS\n";
	 }
	 elsif ($event->mask & IN_OPEN) {
	 	print "$event->{name} IN_OPEN\n";
	 }
   }
#   printf "mask\t%d\n", $_->mask foreach @events ; 
 }

